<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('对账订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>订单编号：</p>
                            <input name="orderSn" type="text"/>
                        </li>
                        <li class="select-time">
                            <p>对账状态：</p>
                            <select name="account" heigh="80px">
                                <option>未对账</option>
                                <option>已对账</option>
                                <option>异常</option>
                            </select>
                        </li>
                        <li>
                            <p>店铺ID：</p>
                            <input name="storeId" type="text"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="mall:order:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
            <a class="btn btn-warning" onclick="checkModal()">
                结算
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table data-mobile-responsive="true" id="bootstrap-table"></table>
        </div>
    </div>
</div>
<!-- 填写单号Modal-->
<div class="modal inmodal" id="checkModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated">
            <div class="modal-body">
                <div class="form-group">
                    <label>店铺ID</label>
                    <input type="text" placeholder="请输入店铺ID" class="form-control" id="storeId" required>
                </div>
                <div class="form-group">
                    <label>开始时间</label>
                    <input type="text" placeholder="请输入开始时间" class="form-control" id="startTime" required>
                </div>
                <div class="form-group">
                    <label>结束时间</label>
                    <input type="text" placeholder="请输入结束" class="form-control" id="endTime" required>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal" onclick="closeSettlementModal()">
                    取消
                </button>
                <button type="button" class="btn btn-primary" onclick="submitSettlement()">确定</button>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('mall:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('mall:order:remove')}]];
    var prefix = ctx + "mall/order";
    var options = {
        url: prefix + "/list",
        createUrl: prefix + "/add",
        detailUrl: prefix + "/detail",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        exportUrl: prefix + "/export",
        modalName: "订单",
        columns: [{
            checkbox: true
        },
            {
                field: 'id',
                title: '订单id',
                visible: false
            },
            {
                field: 'memberId',
                title: '用户编号'
            },
            {
                field: 'storeId',
                title: '店铺ID'
            },
            {
                field: 'orderSn',
                title: '订单编号'
            },
            {
                field: 'memberUsername',
                title: '用户帐号'
            },
            {
                field: 'totalAmount',
                title: '订单总金额'
            },
            {
                field: 'payAmount',
                title: '应付金额'
            },
            {
                field: 'freightAmount',
                title: '运费金额'
            },
            {
                field: 'couponAmount',
                title: '优惠券抵扣金额'
            },

            {
                field: 'payType',
                title: '支付方式'
            },
            {
                field: 'checkStatus',
                title: '对账状态'
            },
        ]
    };
    $(function () {
        $.table.init(options);
    });

    /**
     * 显示结算modal
     */
    function checkModal() {
        // 显示modal
        $("#checkModal").show();
    }

    /**
     * 提交结算
     */
    function submitSettlement() {
        var storeId = $("#storeId").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        // ajax
        $.ajax({
            //提交数据的类型 POST GET
            type: "POST",
            //提交的网址
            url: ctx + "finance/financeSettlement/settlement",
            //提交的数据   该参数为属性值类型的参数
            //（和url?Name="sanmao"&Password="sanmapword"一样）后台若为SpringMVC接受，注明@RequestParam
            data: {storeId: storeId, startTime: startTime, endTime: endTime},
            //返回数据的格式
            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
            //在请求之前调用的函数
            beforeSend: function () {
                //$("#msg").html("logining");
            },
            //成功返回之后调用的函数
            success: function (data) {
                console.log(data)
                if(data.code==0){
                    // 结算成功
                    $.modal.alertSuccess("结算成功");
                    $("#storeId").val("");
                    $("#startTime").val("");
                    $("#endTime").val("");
                    //$("#msg").html(decodeURI(data));
                    $("#checkModal").hide();
                    $.table.init(options);
                }else {
                    $.modal.alertWarning(data.msg);
                    return false;
                }
            },
            //调用执行后调用的函数
            complete: function (XMLHttpRequest, textStatus) {
                // alert(XMLHttpRequest.responseText);
                // alert(textStatus);
                //HideLoading();
            },
            //调用出错执行的函数
            error: function () {
                //请求出错处理
            }
        });
    }

    /**
     * 取消结算
     */
    function closeSettlementModal() {
        $("#checkModal").hide();
    }

</script>
</body>
</html>
